package com.hotel.dao.impl;

import com.hotel.dao.OrderDetailDao;
import com.hotel.utils.JdbcUtils;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.util.List;
import java.util.Map;

/**
 * Created by LinYaTing on 2018/11/28 11:57
 */
public class OrderDetailDaoImpl implements OrderDetailDao {

    @Override
    public List<Map<String, Object>> findAll(Integer id) {
        String sql = "SELECT od.food_id foodId,f.foodName,f.price,od.foodCount FROM orderdetail od LEFT JOIN orders o ON od.orders_id=o.id LEFT JOIN food f ON od.food_id=f.id WHERE o.id=?";
        try {
            return JdbcUtils.getQueryRunner().query(sql, new MapListHandler(),id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
